import { Global, Module } from '@nestjs/common';
import { RedisService } from './redis.service';
import { RedisController } from './redis.controller';
import { createClient } from 'redis';

@Global() // 全局注册
@Module({
  controllers: [
    RedisController
  ],
  providers: [
    RedisService,
    {
      provide: 'REDIS_CLIENT',
      async useFactory() {
        const client = createClient({
          socket: {
            host: 'localhost',
            port: 6379
          },
          database: 0
        })
        await client.connect()
        return client
      }
    }
  ],
  exports: [RedisService] // 使其他模块可以引用
})
export class RedisModule {}
